#include "Service.h"
#undef signals
extern "C"
{
    #include <libnotify/notify.h>
    #include <gio/gio.h>
}
#define signals public
#include <QDebug>
#include "configure.cmake.h"

namespace NotifyService
{
Service::Service(QObject *parent) : QObject(parent), m_success(true)
{
    if (!notify_is_initted()) {
        m_success = notify_init(APP_ID);
    }
}

void Service::send(const QString &title, const QString &message)
{
    send(title, message, NotificationLevel::INFO);
}

void Service::send(const QString &title, const QString &message, const NotificationLevel level)
{
    qDebug() << "Sending message: " << title << ": " << message;
    const char *icon;
    switch (level) {
    case NotificationLevel::INFO:
        icon = "dekko";
        break;
    case NotificationLevel::WARNING:
        icon = "dialog-warning";
        break;
    case NotificationLevel::CRITICAL:
        icon = "dialog-error";
        break;
    default:
        icon = NULL;
    }
    NotifyNotification *notification = notify_notification_new(title.toUtf8().data(),
                                                               message.toUtf8().data(),
                                                               icon);
    // TODO: add action callbacks to open app on click
    notify_notification_show(notification, NULL);
}

bool Service::serviceAvailable() const
{
    return m_success;
}

}
